﻿#include<bits/stdc++.h>
using namespace std;
#include<unordered_map>


class Solution
{
public:
    int smallestNumber(int n)
    {
        int left = 0, right = 11;
        int x;
        while (left < right)
        {
            int mid = (right + left) / 2;
            if ((int)pow(2, mid) - 1 >= n)
            {
                right = mid;
                x = (int)pow(2, mid) - 1;
            }
            else
            {
                left = mid + 1;
            }
        }
        return x;
    }
};


class Solution
{
public:
    int smallestNumber(int n)
    {

        int num = bit_width((unsigned)n);//计算n的二进制长度
        return (1 << num) - 1;
    }
};


//2
class Solution
{
public:
    int getLargestOutlier(vector<int>& nums)
    {
        unordered_map<int, int>hash;
        int ans = -0x3f3f3f3f;
        int sum = 0;
        for (auto it : nums)
        {
            hash[it]++;
            sum += it;
        }

        for (auto it : nums)
        {
            hash[it]--;
            if ((sum - it) % 2 == 0 && hash[(sum - it) / 2] > 0)//本质上就是，2s+x=sum,s为和，x为异常值，sum为总和
                //枚举异常值，只要剩下的和为偶数并且该s存在，就说明此时为一次异常值
            {
                ans = max(ans, it);
            }
            hash[it]++;
        }
        return ans;
    }
};